package com.usian.article.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.apis.article.AuthorControllerApi;
import com.usian.article.service.ApAuthorService;
import com.usian.model.article.pojos.ApAuthor;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/api/v1/author")
public class ApAuthorController implements AuthorControllerApi {
    @Autowired
    ApAuthorService service;

    @Override
    @GetMapping("/findByUserId/{id}")
    public ApAuthor findByUserId(@PathVariable Integer id) {
        return service.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(id!=null,ApAuthor::getUserId,id));
    }

    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody ApAuthor apAuthor) {
        apAuthor.setCreatedTime(new Date());
        service.save(apAuthor);
        return ResponseResult.okResult(apAuthor);
    }
    @GetMapping("/findByAuthorId/{id}")
    public ApAuthor findByAuthorId(@PathVariable("id") Integer id){
        ApAuthor apAuthor = service.getById(id);
        return apAuthor;
    }
}
